<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>后台管理系统</title>
        <meta name="author" content="BaiYY"/>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
        <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
        <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    </head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;">
        <section class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>游戏ID</th>
                        <th>微信昵称</th>
                        <th>房卡张数</th>
                        <th id="showCoin">{:L(GAME_COUN_NUM)}</th>
                        <th>创建时间</th>
                        <th>删除</th>
                    </tr>
                </thead>
                <tbody id="dataList"></tbody>
            </table>
        </section>
        <div id="playerPage">
            <a href="javascript:void(0)" id="prev">上一页</a>
            <a href="javascript:void(0)" id="page"></a>
            <a href="javascript:void(0)" id="next">下一页</a>
            <span>一共</span>
            <a href="javascript:void(0)" id="totalPage"></a>
            <span>页</span>
        </div>

        <div id="bg-models">
            <div id="bg-contents">
                <i class="glyphicon glyphicon-remove" id="btn-closed"></i>
                <div class="title_dialog">系统提示！</div>
                <div class="discription_dialog">确定要删除该成员？</div>
                <div class="footer_dialog">
                    <button class="btn btn-primary" id="btn-ok">确定</button>
                    <button class="btn btn-primary" id="btn-off">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var showCoin = $.trim($("#showCoin").text());
            if(showCoin == '' || showCoin == 'GAME_COUN_NUM') {
                $("#showCoin").hide();
            }
            $.ajax({
                type:'get',
                url:"{:U('Admin/Main/getGroupMember')}",
                success: function (data) {
                    var count = Math.ceil(data.count/10);
//                    console.log(data);
                    if(data != 'error') {
                        var str = '';
                       for(var i=0;i<data.arr.length;++i) {
                           if(showCoin == '' || showCoin == null) {
                               str += '<tr><td class="uid">'+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td><td><button class='btn btn-primary btn-sm' onclick='delClick(this)'>删除</button></td></tr>";
                           }else{
                               str += '<tr><td class="uid">'+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td><td><button class='btn btn-primary btn-sm' onclick='delClick(this)'>删除</button></td></tr>";
                           }
                       }
                       $("#dataList").html(str);
                       $("#page").text(1);
                       $("#totalPage").text(count);
                    }else{
                        $("#dataList").html("暂时没有成员");
                    }
                }
            });
        });
        $("#prev").on("click",function (ev) {
            var page = $.trim($("#page").text());
            if(page == 1) {
                page = 1;
                return false;
            }else if($("#page").text() > 1) {
                page = page - 1;
            }
            var start = $("#dataList tr:first").find("td.uid").text();
            var action = -1;
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/getGroupMember')}",
                dataType:"json",
                data:{"start":start,"action":action,"page":page},
                success:function (data) {
                    if(data != 'error') {
                        var str = '';
                        for(var i=0;i<data.arr.length;++i) {
                            str += '<tr><td class="uid">'+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td><td><button class='btn btn-primary' onclick='delClick(this)'>删除</button></td></tr>";
                        }
                        $("#dataList").html(str);
                        $("#page").text(page);
                    }
                }
            })

        });


        $("#next").on("click",function (e) {
            var page = $.trim($("#page").text());
            page = ++page;
            var totalPage = $.trim($("#totalPage").text())/1;
            if(page > totalPage) {
                return false;
            }
            var start = $("#dataList tr:last").find("td.uid").text();
            var action = 1;
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/getGroupMember')}",
                dataType:"json",
                data:{"start":start,"action":action,"page":page},
                success: function (data) {
                    var str = '';
                    for(var i=0;i<data.arr.length;++i) {
                        str += '<tr><td class="uid">'+data.arr[i]._id+"</td><td>"+data.arr[i].info.name+"</td><td>"+data.arr[i].status.card+"</td><td>"+data.arr[i].status.coin+"</td><td>"+getLocalTime(data.arr[i].info.createTime)+"</td><td><button class='btn btn-primary' onclick='delClick(this)'>删除</button></td></tr>";
                    }
                    $("#dataList").html(str);
                    $("#page").text(page);
                }
            });
        });


        function delClick(This) {
            var uid = $(This).closest("tr").find("td.uid").text();
            $("#bg-models").fadeIn();
            $("#btn-ok").on("click",function () {
                $.ajax({
                    type:'get',
                    url:"{:U('Admin/Main/delCroupMember')}?uid="+uid,
                    success: function (data) {
                        if(data == 'success') {
                            window.location.href="{:U('Admin/Main/groupMember')}";
                        }else if(data == 'error'){
                            window.location.href="{:U('Admin/Main/groupMember')}";
                        }
                    }
                });
            })
            $("#btn-closed").on("click",function () {
                $("#bg-models").hide();
            });
            $("#btn-off").on("click",function () {
                $("#bg-models").hide();
            });
        }
    </script>
</body>
</html>